package com.neuedu.bases;
import com.neuedu.configs.PathConfig;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;


/**
 * @author Wujg(helpbusiness @ 126.com)
 * @date 2023/8/22
 */

public class HandleYaml {
    private String filePath;

    public HandleYaml(String fileName) {
        if (fileName != null) {
            this.filePath = PathConfig.path_test_datas + File.separator + fileName;
            System.out.println(this.filePath);
        } else {
            this.filePath =PathConfig.path_test_datas + File.separator + "object_datas.yaml";
        }
        // this.data = this.getData();
    }

    public Map<String, Object> getData() {
        File file = new File(this.filePath);
        try (FileInputStream inputStream = new FileInputStream(file)) {
            Yaml yaml = new Yaml();
            Map<String, Object> data = yaml.load(inputStream);
            return data;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}